"use strict";
cc._RF.push(module, '813acngPPBGtaskZruwmOCF', 'MenuLayoutController');
// scripts/MenuLayoutController.ts

"use strict";
// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var AudioManager_1 = require("./util/AudioManager");
var Config_1 = require("./util/Config");
var LocalStorageManager_1 = require("./util/LocalStorageManager");
var Tools_1 = require("./util/Tools");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var MenuLayoutController = /** @class */ (function (_super) {
    __extends(MenuLayoutController, _super);
    function MenuLayoutController() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.sideBg = null; //背景
        _this.sideBtnMenu = null; //菜单按钮
        _this.sideBtnInfo = null; //游戏介绍按钮
        _this.sideBtnSoundOnLayout = null; //音效按钮 父布局
        _this.sideBtnSoundOn = null; //音效按钮
        _this.sideBtnSoundOff = null; //音效按钮
        _this.sideBtnMusicOnLayout = null; //音乐按钮 父布局
        _this.sideBtnMusicOn = null; //音乐按钮
        _this.sideBtnMusicOff = null; //音乐按钮
        _this.btnopen = null;
        // 全屏点击遮罩，用于点击屏幕任意位置关闭设置面板
        _this.clickMask = null;
        _this.sideBtnMenuPosion = null;
        _this.sideBtnInfoPosion = null;
        _this.sideBtnSoundOnPosion = null;
        _this.sideBtnMusicOnPosion = null;
        _this.isExpand = false; //是否是展开
        _this.isLock = false; //是否是锁定
        _this.music = true;
        _this.sound = true;
        return _this;
        // update (dt) {}
    }
    MenuLayoutController.prototype.onLoad = function () {
        // 初始化点击遮罩
        this.initClickMask();
    };
    MenuLayoutController.prototype.onEnable = function () {
        this.music = LocalStorageManager_1.LocalStorageManager.GetInstance().getMusicSwitch();
        this.sound = LocalStorageManager_1.LocalStorageManager.GetInstance().getSoundSwitch();
        this.setMusicSwitch(this.music);
        this.setSoundSwitch(this.sound);
        // 断线重连/页面恢复时，强制重置到“收起”状态，避免按钮叠在一起、背景未隐藏
        this.collapseImmediately();
    };
    MenuLayoutController.prototype.start = function () {
        var _this = this;
        this.sideBtnMenuPosion = this.sideBtnMenu.position;
        this.sideBtnInfoPosion = this.sideBtnInfo.position;
        this.sideBtnSoundOnPosion = this.sideBtnSoundOnLayout.position;
        this.sideBtnMusicOnPosion = this.sideBtnMusicOnLayout.position;
        Tools_1.Tools.imageButtonClick(this.sideBtnMenu, Config_1.Config.buttonRes + 'side_btn_menu_normal', Config_1.Config.buttonRes + 'side_btn_menu_pressed', function () {
            if (_this.isLock) {
                return;
            }
            _this.isLock = true;
            if (_this.isExpand) {
                _this.input(function () {
                    _this.isExpand = false; // 收起后设置为false
                    _this.isLock = false;
                });
            }
            else {
                _this.output(function () {
                    _this.isExpand = true; // 展开后设置为true
                    _this.isLock = false;
                });
            }
        });
        Tools_1.Tools.imageButtonClick(this.sideBtnInfo, Config_1.Config.buttonRes + 'side_btn_info_normal', Config_1.Config.buttonRes + 'side_btn_info_pressed', function () {
            if (_this.isLock) {
                return;
            }
            _this.isLock = true;
            _this.input(function () {
                _this.isExpand = false; // 收起后设置为false
                _this.isLock = false;
            });
            if (_this.infoClick) {
                _this.infoClick();
            }
        });
        Tools_1.Tools.imageButtonClick(this.sideBtnSoundOn, Config_1.Config.buttonRes + 'side_btn_sound_on_normal', Config_1.Config.buttonRes + 'side_btn_sound_on_pressed', function () {
            _this.sound = !_this.sound;
            LocalStorageManager_1.LocalStorageManager.GetInstance().setSoundSwitch(_this.sound);
            _this.setSoundSwitch(_this.sound);
        });
        Tools_1.Tools.imageButtonClick(this.sideBtnSoundOff, Config_1.Config.buttonRes + 'side_btn_sound_off_normal', Config_1.Config.buttonRes + 'side_btn_sound_off_pressed', function () {
            _this.sound = !_this.sound;
            LocalStorageManager_1.LocalStorageManager.GetInstance().setSoundSwitch(_this.sound);
            _this.setSoundSwitch(_this.sound);
        });
        Tools_1.Tools.imageButtonClick(this.sideBtnMusicOn, Config_1.Config.buttonRes + 'side_btn_music_on_normal', Config_1.Config.buttonRes + 'side_btn_music_on_pressed', function () {
            _this.music = !_this.music;
            LocalStorageManager_1.LocalStorageManager.GetInstance().setMusicSwitch(_this.music);
            _this.setMusicSwitch(_this.music);
        });
        Tools_1.Tools.imageButtonClick(this.sideBtnMusicOff, Config_1.Config.buttonRes + 'side_btn_music_off_normal', Config_1.Config.buttonRes + 'side_btn_music_off_pressed', function () {
            _this.music = !_this.music;
            LocalStorageManager_1.LocalStorageManager.GetInstance().setMusicSwitch(_this.music);
            _this.setMusicSwitch(_this.music);
        });
    };
    /**
     * 立即收起：停止一切补间，重置所有节点位置/可见性/透明度与背景
     * 用于断线重连、场景恢复时保证UI为收起状态
     */
    MenuLayoutController.prototype.collapseImmediately = function () {
        // 停止补间，避免状态叠加
        this.stopAllMenuTweens();
        // 重置功能面板按钮布局到初始位置与不可见
        if (this.sideBtnInfo) {
            if (this.sideBtnInfoPosion) {
                this.sideBtnInfo.position = new cc.Vec3(this.sideBtnInfoPosion.x, this.sideBtnInfoPosion.y, 0);
            }
            this.sideBtnInfo.opacity = 0;
            this.sideBtnInfo.active = false;
        }
        if (this.sideBtnSoundOnLayout) {
            if (this.sideBtnSoundOnPosion) {
                this.sideBtnSoundOnLayout.position = new cc.Vec3(this.sideBtnSoundOnPosion.x, this.sideBtnSoundOnPosion.y, 0);
            }
            this.sideBtnSoundOnLayout.opacity = 0;
            this.sideBtnSoundOnLayout.active = false;
        }
        if (this.sideBtnMusicOnLayout) {
            if (this.sideBtnMusicOnPosion) {
                this.sideBtnMusicOnLayout.position = new cc.Vec3(this.sideBtnMusicOnPosion.x, this.sideBtnMusicOnPosion.y, 0);
            }
            this.sideBtnMusicOnLayout.opacity = 0;
            this.sideBtnMusicOnLayout.active = false;
        }
        // 背景重置与隐藏
        if (this.sideBg) {
            this.sideBg.anchorY = 1;
            this.sideBg.height = 76;
            this.sideBg.opacity = 0;
            this.sideBg.active = false;
        }
        // 关闭点击遮罩
        this.disableClickMask();
        // 重置状态机
        this.isExpand = false;
        this.isLock = false;
    };
    /**
     * 停止所有相关节点的补间，避免补间叠加导致的错乱
     */
    MenuLayoutController.prototype.stopAllMenuTweens = function () {
        if (this.sideBtnInfo)
            cc.Tween.stopAllByTarget(this.sideBtnInfo);
        if (this.sideBtnSoundOnLayout)
            cc.Tween.stopAllByTarget(this.sideBtnSoundOnLayout);
        if (this.sideBtnMusicOnLayout)
            cc.Tween.stopAllByTarget(this.sideBtnMusicOnLayout);
        if (this.sideBg)
            cc.Tween.stopAllByTarget(this.sideBg);
    };
    MenuLayoutController.prototype.setMusicSwitch = function (switchType) {
        if (switchType) {
            this.sideBtnMusicOn.active = true;
            this.sideBtnMusicOff.active = false;
        }
        else {
            this.sideBtnMusicOn.active = false;
            this.sideBtnMusicOff.active = true;
        }
        if (this.music) {
            AudioManager_1.AudioManager.playBgm();
        }
        else {
            AudioManager_1.AudioManager.stopBgm();
        }
    };
    MenuLayoutController.prototype.setSoundSwitch = function (switchType) {
        if (switchType) {
            this.sideBtnSoundOn.active = true;
            this.sideBtnSoundOff.active = false;
        }
        else {
            this.sideBtnSoundOn.active = false;
            this.sideBtnSoundOff.active = true;
        }
    };
    MenuLayoutController.prototype.setClick = function (infoClick) {
        this.infoClick = infoClick;
    };
    //展开
    MenuLayoutController.prototype.output = function (callbacks) {
        var _this = this;
        cc.tween(this.sideBtnInfo)
            .call(function () {
            _this.sideBtnInfo.active = true;
        })
            .to(0.2, {
            position: new cc.Vec3(this.sideBtnInfoPosion.x, this.sideBtnInfoPosion.y - 64, 0),
            opacity: 255
        }, { easing: 'quadIn' }) // 可用 'sineInOut', 'cubicOut' 等
            .start();
        cc.tween(this.sideBtnSoundOnLayout)
            .call(function () {
            _this.sideBtnSoundOnLayout.active = true;
        })
            .to(0.2, {
            position: new cc.Vec3(this.sideBtnSoundOnPosion.x, this.sideBtnSoundOnPosion.y - 128, 0),
            opacity: 255
        }, { easing: 'quadIn' }) // 可用 'sineInOut', 'cubicOut' 等
            .start();
        cc.tween(this.sideBtnMusicOnLayout)
            .call(function () {
            _this.sideBtnMusicOnLayout.active = true;
        })
            .to(0.2, {
            position: new cc.Vec3(this.sideBtnMusicOnPosion.x, this.sideBtnMusicOnPosion.y - 192, 0),
            opacity: 255
        }, { easing: 'quadIn' }) // 可用 'sineInOut', 'cubicOut' 等
            .start();
        this.sideBg.anchorY = 1;
        cc.tween(this.sideBg)
            .call(function () {
            _this.sideBg.active = true;
        })
            .to(0.2, { height: 268, opacity: 255 }, { easing: 'quadIn' })
            .call(function () {
            callbacks();
        })
            .start();
        this.enableClickMask();
    };
    //收起
    MenuLayoutController.prototype.input = function (callbacks) {
        var _this = this;
        cc.tween(this.sideBtnInfo)
            .to(0.2, {
            position: new cc.Vec3(this.sideBtnInfoPosion.x, this.sideBtnInfoPosion.y, 0),
            opacity: 0
        }, { easing: 'quadIn' }) // 可用 'sineInOut', 'cubicOut' 等
            .call(function () {
            _this.sideBtnInfo.active = false;
        })
            .start();
        cc.tween(this.sideBtnSoundOnLayout)
            .to(0.2, {
            position: new cc.Vec3(this.sideBtnSoundOnPosion.x, this.sideBtnSoundOnPosion.y, 0),
            opacity: 0
        }, { easing: 'quadIn' }) // 可用 'sineInOut', 'cubicOut' 等
            .call(function () {
            _this.sideBtnSoundOnLayout.active = false;
        })
            .start();
        cc.tween(this.sideBtnMusicOnLayout)
            .to(0.2, {
            position: new cc.Vec3(this.sideBtnMusicOnPosion.x, this.sideBtnMusicOnPosion.y, 0),
            opacity: 0
        }, { easing: 'quadIn' }) // 可用 'sineInOut', 'cubicOut' 等
            .call(function () {
            _this.sideBtnMusicOnLayout.active = false;
        })
            .start();
        this.sideBg.anchorY = 1;
        cc.tween(this.sideBg)
            .to(0.2, { height: 76, opacity: 0 }, { easing: 'quadIn' })
            .call(function () {
            _this.sideBg.active = false;
            // 收起后禁用遮罩，防止遮罩残留导致点击穿透或叠层
            _this.disableClickMask();
            callbacks();
        })
            .start();
    };
    MenuLayoutController.prototype.onDisable = function () {
        // 组件关闭时停止补间，避免回到前台或重连后补间继续执行造成叠加
        this.stopAllMenuTweens();
    };
    /**
     * 初始化点击遮罩
     */
    MenuLayoutController.prototype.initClickMask = function () {
        // 创建一个全屏的透明遮罩节点
        this.clickMask = this.btnopen;
        // 添加Button组件，确保能接收点击事件
        var button = this.clickMask.addComponent(cc.Button);
        button.transition = cc.Button.Transition.NONE; // 不要视觉过渡效果
        // 添加点击事件监听
        button.node.on('click', this.onClickMaskClick, this);
        // 默认禁用
        this.clickMask.active = false;
    };
    /**
     * 启用点击遮罩
     */
    MenuLayoutController.prototype.enableClickMask = function () {
        if (this.clickMask) {
            this.clickMask.active = true;
        }
    };
    /**
     * 禁用点击遮罩
     */
    MenuLayoutController.prototype.disableClickMask = function () {
        if (this.clickMask) {
            this.clickMask.active = false;
        }
    };
    /**
     * 点击遮罩的处理函数
     */
    MenuLayoutController.prototype.onClickMaskClick = function () {
        var _this = this;
        this.input(function () {
            _this.disableClickMask();
            _this.isLock = false; // 重置锁定状态，允许再次点击按钮
            _this.isExpand = false; // 重置展开状态
        });
    };
    MenuLayoutController.prototype.onDestroy = function () {
        // 清理点击遮罩
        if (this.clickMask && this.clickMask.isValid) {
            this.clickMask.off('click', this.onClickMaskClick, this);
            this.clickMask.removeFromParent();
            this.clickMask = null;
        }
    };
    __decorate([
        property(cc.Node)
    ], MenuLayoutController.prototype, "sideBg", void 0);
    __decorate([
        property(cc.Node)
    ], MenuLayoutController.prototype, "sideBtnMenu", void 0);
    __decorate([
        property(cc.Node)
    ], MenuLayoutController.prototype, "sideBtnInfo", void 0);
    __decorate([
        property(cc.Node)
    ], MenuLayoutController.prototype, "sideBtnSoundOnLayout", void 0);
    __decorate([
        property(cc.Node)
    ], MenuLayoutController.prototype, "sideBtnSoundOn", void 0);
    __decorate([
        property(cc.Node)
    ], MenuLayoutController.prototype, "sideBtnSoundOff", void 0);
    __decorate([
        property(cc.Node)
    ], MenuLayoutController.prototype, "sideBtnMusicOnLayout", void 0);
    __decorate([
        property(cc.Node)
    ], MenuLayoutController.prototype, "sideBtnMusicOn", void 0);
    __decorate([
        property(cc.Node)
    ], MenuLayoutController.prototype, "sideBtnMusicOff", void 0);
    __decorate([
        property(cc.Node)
    ], MenuLayoutController.prototype, "btnopen", void 0);
    MenuLayoutController = __decorate([
        ccclass
    ], MenuLayoutController);
    return MenuLayoutController;
}(cc.Component));
exports.default = MenuLayoutController;

cc._RF.pop();